

import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Scanner;

public class ConfirmTaxi implements Runnable {
	private String imei;
	private String customerPhone;
	private int status;
	private static InetAddress host;
	private static int port = 1243;

	public ConfirmTaxi(String imei, String customerPhone, int status) {
		this.imei = imei;
		this.customerPhone = customerPhone;
		this.status = status;
	}

	@Override
	public void run() {
		try {
			host = InetAddress.getLocalHost();
		} catch (UnknownHostException uhEx) {
			System.out.println("Host ID not found!");
			System.exit(1);
		}
		Socket link = null;
		try {
			link = new Socket(host, port);
			Scanner input = new Scanner(link.getInputStream());
			PrintWriter output = new PrintWriter(link.getOutputStream(), true);
			System.out.println("Connected");
			String message, response;

			message = imei + "," + customerPhone + "," + String.valueOf(status);
			output.println(message);
			System.out.println("Send data ....");
			link.close();
			output.close();

		} catch (IOException ioEx) {
			System.out.println("No server listen");
		} finally {
			if (link != null) {
				try {

					System.out.println("\n* Closing connection... *");
					link.close();
				} catch (IOException ioEx) {
					System.out.println("Unable to disconnect!");
					System.exit(1);
				}
			}
		}

	}
}
